<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
    const getNext = (n) => {
        n = String(n)
            //for of可以让代码更好读
        let sum = 0;
        for (let num of n) {
            sum += Math.pow(num, 2)
        }
        return sum;
    }

    var isHappy = function(n) {
        while (n !== 1) {
            n = getNext();

        }
        return true;
    }
    console.log(isHappy(19));
</script>

<body>

</body>

</html>